home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 52
/
Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso
/
Aminet
/
game
/
board
/
RXDraughts.lha
/
RXDraughts.rexx
< prev
Wrap
OS/2 REXX Batch file
|
2002-10-13
|
16KB
|
639 lines
/* RXDraughts 2.0 ©2002 Michael Trebilcock
Changes since 1.9:
GUI is not complete.
- Optimizations.
- Moved code to a FMove() function.
- Forced jumping (not completed). (Huffing not)
- "Game over" code finished.
To do:
- Add huffing support (Soon)
- Pieces jumped flash for half a second. (Maybe)
- Last valid move can be shown visibly. (Maybe)
- Chat option for online multiplayer. (Doubt it)
Known bugs:
- None
*/
/* Configuration */
Huff = "0" /* 0 = Forced jumping, 1 = Huffing enabled */
Delay = "0" /* Slow down the computer (50 = 1 sec) */
/* End Configuration */
Signal On Halt
Signal On Break_C
Call AddLib("rexxtricks.library","0","-30","0")
Call AddLib("rexxdossupport.library","0","-30","0")
Call AddLib("rexxsupport.library","0","-30","0")
Call AddLib("rexxreqtools.library","0","-30","0")
Play="B"
DO i=1 TO 8
Let=d2c(64+i)
Let.Let=i
Let.i=Let
End
DO i=1 TO 32
P.i=""
End
DO i=1 TO 12
P.i="w"
End
DO i=21 TO 32
P.i="b"
End
PosX="b";PosX.PosX="1"
PosX="B";PosX.PosX="31"
PosX="w";PosX.PosX="61"
PosX="W";PosX.PosX="91"
PosX="";PosX.PosX="121"
Move2="<none>"
CJump="0"
Call NewGame()
Text="Human VS Human"
IF Opt="2" THEN Text="Human VS Computer"
IF Opt="3" THEN Text="Computer VS Computer"
IF Opt="4" THEN Text="Human VS Human (TCP/IP)"
IF TFile~="" THEN DO
IF ~Open(File,TFile,"R") THEN DO
SAY "Unable to open "TFile
Exit
End
DO i=1 TO 32
P.i=ReadLn(File)
End
Call Close(File)
Play=Upper(Play)
End
IF Opt="4" THEN DO
IF Plr="1" THEN DO
SAY "Attemping to connect to "IP" on port 998..."
DO UNTIL Open(TCP,"TCP:"IP"/998","R")
Call Delay(50)
End
SAY "Connected, sending info.."
DO i=1 TO 32
Call WriteLn(TCP,P.i)
End
Call WriteLn(TCP,Play)
Call Close(TCP)
SAY "Sent, starting game."
End
ELSE DO
SAY "Waiting for player one..."
Call Delete("T:Board.tmp")
ADDRESS COMMAND "Run >NIL: Copy TCP:998 T:Board.tmp"
DO UNTIL Open(File,"T:Board.tmp","R")
Call Delay(50)
End
SAY "Player one connected, receiving info.."
DO i=1 TO 32
P.i=ReadLn(File)
End
Play=ReadLn(File)
Call Close(File)
SAY "Info received, starting game."
End
Opt="1"
End
Call GUI()
DO UNTIL End="1"
Error="0";Jump="0"
King="0";HJump="0"
SAY ""
IF Play="B" THEN SAY "Black players turn: "
ELSE SAY "White players turn: "
SAY "(I.E: A2 B1 to move from A2 to B1)"
SAY "(I.E: F1 D3 B5 etc.. for double/triple jumps)"
SAY "Last valid move: "Move2
IF Opt="2"&Play="W"|Opt="3" THEN DO
Call FMove()
IF Jump="1"&ValidJps~="" THEN DO
SAY "Jump(s) found."
SAY "Jumps can be made from squares "ValidJps
SAY "Selecting a random jump.."
Words=Words(ValidJps)
Num3=Word(ValidJps,Rand(1,Words))
SAY "Piece selected is "Num3
SAY "Jumps are "TJP.Num3
SAY "Selecting random square to jump over"
Words=Words(TJP.Num3)
Num4=Word(TJP.Num3,Rand(1,Words))
Parse Var Num4 TheSq"/"GNum2"/"Num4
SAY "Square to jump over is "GNum2
P.GNum2=""
End
ELSE IF CJump~="1"&ValidSqs~="" THEN DO
SAY "Randomly selecting a moveable piece.."
Words=Words(ValidSqs)
Num3=Word(ValidSqs,Rand(1,Words))
SAY "Piece selected is "Num3
SAY "Squares to move to are "TP.Num3
SAY "Selecting random square to move to"
Words=Words(TP.Num3)
Num4=Word(TP.Num3,Rand(1,Words))
SAY "Square to move to is "Num4
End
Let4=0
IF Play="W"&Num4>28&Num4<33 THEN Let4=8
IF Play="B"&Num4>0&Num4<5 THEN Let4=1
IF CJump="1"&Jump="0" THEN DO
SAY "Cannot make another jump with the same piece"
CJump="0";Error="1"
IF Play="B" THEN Play="W"
ELSE Play="B"
End
End
ELSE IF End~="1" THEN DO
IF CJump~="2" THEN DO
IF Plr="1"&Play="W"|Plr="2"&Play="B" THEN DO
SAY "Waiting for opponent to make a move.."
ADDRESS COMMAND "Copy TCP:998 T:RXDMove.tmp"
Call Open(File,"T:RXDMove.tmp","R")
Move=ReadLn(File)
Call Close(File)
End
ELSE DO
Call FMove()
IF End~="1" THEN Call GMove(1)
End
End
Move=Upper(Move)
IF Move="EOF" THEN Call Break_C()
IF W2=SG THEN DO
TFile=rtgetstring("","Enter filename:","RXDraughts","Save")
IF ~Open(File,TFile,"W") THEN DO
SAY "Unable to open "TFile
End
ELSE DO
DO i=1 TO 32
Call WriteLn(File,P.i)
End
Call Close(File)
SAY "Game saved.."
Error="1"
End
End
Let=Left(Move,1);Num=SubStr(Move,2,1)
Let2=SubStr(Move,4,1);Num2=SubStr(Move,5,1)
Let3=Let.Let;Let4=Let.Let2
End
IF End="1" THEN Error="1"
IF Error="0"&Play="B"&Opt<3|Error="0"&Opt="1" THEN DO
Call Grid(Let3""Num);Num3=GNum2
Call Grid(Let4""Num2);Num4=GNum2
IF Upper(P.Num3)=P.Num3 THEN King="1"
Squares=Compress(Translate(Num-Num2,"","-"))
Lets=Compress(Translate(Let3-Let4,"","-"))
SELECT
WHEN Play="B"&Upper(P.Num3)="W"|Play="W"&Upper(P.Num3)="B" THEN DO
SAY "You cannot move the other players piece."
Error="1"
End
WHEN P.Num3="" THEN DO
SAY "Invalid move. You cannot move a blank square."
Error="1"
End
WHEN Play="B"&Let4-Let3>0&King="0"|Play="W"&Let3-Let4>0&King="0" THEN DO
SAY "Invalid move. Only kings can move backwards."
Error="1"
End
WHEN Squares>1|Lets>1|Num=Num2|Let=Let2 THEN DO
IF Play="B" THEN DO
IF Num2=Num-2|Num2=Num+2 THEN IF Let4=Let3-2|Let4=Let3+2 THEN HJump="1"
IF Let4=Let3+2&King="0" THEN Error="1"
End
IF Play="W" THEN DO
IF Num2=Num-2|Num2=Num+2 THEN IF Let4=Let3+2|Let4=Let3-2 THEN HJump="1"
IF Let4=Let3-2&King="0" THEN Error="1"
End
IF HJump="0" THEN DO
IF Error="1" THEN SAY "Invalid move. Only kings can jump backwards."
ELSE SAY "Invalid move. You may only move diagnally one square unless jumping."
Error="1"
End
ELSE DO
Call Vacant()
IF Error="0" THEN DO
IF Let4-Let3>0 THEN Let5=Let3+1
ELSE Let5=Let3-1
IF Num2=Num-2 THEN Call Grid(Let5""Num-1)
IF Num2=Num+2 THEN Call Grid(Let5""Num+1)
IF Play="W"&Upper(P.GNum2)="W"|Play="B"&Upper(P.GNum2)="B" THEN DO
SAY "You cannot jump over your own piece."
Error="1"
End
IF P.GNum2="" THEN DO
SAY "You cannot jump over a blank square."
Error="1"
End
GNum3=P.GNum2
IF Error="0" THEN P.GNum2=""
End
End
End
OTHERWISE Call Vacant()
End
End
IF Opt="1"|Opt="4"|Opt="2"&Play="B" THEN Jump=HJump
IF Jump="0"&ValidJps~=""&Huff="0" THEN DO
IF Error="0" THEN Call ToPipe('ID 'MG' gt="You must jump!"')
Error="1"
End
IF Error="0" THEN DO
CJump2=CJump
IF CJump="2" THEN CJump="0"
IF Jump="1" THEN DO
SAY "Jumping over piece "GNum2". Moving from "Num3" to "Num4
IF Opt="2"&Play="W"|Opt="3" THEN CJump="1"
IF Play="B"&Opt<3|Play="W"&Opt="1" THEN DO
Parse Var Move M1" "Move
IF Words(Move)>1 THEN CJump="2"
End
IF Play="B"&Let4=1&King="0"|Play="W"&Let4=8&King="0" THEN CJump="0"
End
ELSE SAY "Moving piece "Num3" to "Num4
Call Grid2(Num3);Let=Word(Let,1);GLet=Let.Let""Num
Call Grid2(Num4);Let=Word(Let,1);GLet2=Let.Let""Num
Move2=GLet GLet2
IF Plr="1"&Play="B"|Plr="2"&Play="W" THEN IF CJump2="0" THEN DO
i=0;Sent="0"
IF CJump="2" THEN TMove=M1 Move
ELSE TMove=Move2
DO UNTIL i="5"|Sent="1"
IF ~Open(TCP,"TCP:"IP"/998","W") THEN Call Delay(50)
ELSE DO;Call WriteLn(TCP,TMove);Sent="1";End
i=i+1
End
Call Close(TCP)
SAY i
IF Sent="0" THEN DO
SAY "Unable to send move.."
Call Break_C()
End
End
Piece=P.Num3;P.Num3=""
IF Play="B" THEN P.Num4=Piece
IF Play="B"&Let4=1 THEN P.Num4="B"
IF Play="W" THEN P.Num4=Piece
IF Play="W"&Let4=8 THEN P.Num4="W"
IF CJump~="1"&CJump~="2" THEN DO
IF Play="B" THEN Play="W"
ELSE Play="B"
End
Call GMove()
IF Opt="3" THEN Call Delay(Delay)
End
ELSE IF CJump="2" THEN DO
SAY "Invalid multiple jump.."
CJump="0";Error="1"
IF Play="B" THEN Play="W"
ELSE Play="B"
End
End
IF Play="W" THEN SAY "Game over. Black wins!"
ELSE SAY "Game over. White wins!"
Call rtezrequest("Game over!")
Exit
GUI:
Dis="";Num=1
XY="|1|29|29|0|0|0"
TPipe="PIPE"
IF ~Open(PIPE,"AWNPipe:RXDraughts/xc","RW") THEN DO
SAY "Unable to open GUI, please install AWNPipe:"
Exit
End
Call ToPipe('title "RXDraughts ©2002 Michael Trebilcock" v fw fh m defg')
Call ToPipe('layout v b=5 cj weih=0')
Call ToPipe(' label gt="Welcome to RXDraughts 2.0"')
Call ToPipe(' label gt="©2002 Michael Trebilcock"')
Call ToPipe(' label gt=""')
Call ToPipe('le')
Call ToPipe('layout v b=2 cj weih=0')
MG=ToPipe(' button ro b=0 gt "'Text'"')
Call ToPipe('le')
Call ToPipe('layout b=5')
Call ToPipe(' layout v so weiw=0')
Call ToPipe(' layout v b=0 weih=0')
NG=ToPipe(' button gt="New Game"')
SG=ToPipe(' button gt="Save Game"')
Call ToPipe(' label gt=""')
OG=ToPipe(' button gt="Oops"')
HG=ToPipe(' button gt="Hold"')
Call ToPipe(' label gt=""')
Call ToPipe(' button gt="About"')
QG=ToPipe(' button gt="Quit" c')
Call ToPipe(' le')
Call ToPipe(' layout v b=0')
Call ToPipe(' le')
Call ToPipe(' le')
Call ToPipe(' layout v b=0 sw')
Call ToPipe(' bitmap fn=RXDraughts.iff anim 0|0|0|0|0|0|0')
Call Nums()
DO i=1 TO 8
Call Buttons()
End
Call Nums()
Call ToPipe(' le')
Call ToPipe('le')
Call ToPipe('open')
Call Pieces()
Return 0
GMove:
IF Arg(1)="1" THEN DO
Move="";Done="";Sel="0"
Call ToPipe('con')
DO UNTIL Done="1"
Output=ReadLn(PIPE)
Parse Var Output W1" "W2" "W3
IF W1="close" THEN Call Break_C()
IF W2=NG THEN DO
Move="New Game"
End="1"
End
IF W2=HG THEN DO
IF Sel="0" THEN Sel="1"
ELSE Sel="0"
Call ToPipe('ID 'HG' selected='Sel)
End
IF W2=OG THEN Move=""
IF W2=SG THEN Move="Save Game"
IF W2>24 THEN DO
Call Grid2(GP.W2)
Move=Move""Let.Let""Num" "
End
Call ToPipe('ID 'MG' gt="'Strip(Move,," ")'"')
IF Words(Move)>1&Sel="0" THEN Done="1"
ELSE Call ToPipe('con')
End
IF Words(Move)<2 THEN Error="1"
End
ELSE DO
Call ToPipe('define bitmap anim 121'XY)
Call ToPipe('ID 'BP.Num3' ni=0')
IF Jump="1" THEN DO
Call ToPipe('define bitmap anim 121'XY)
Call ToPipe('ID 'BP.GNum2' ni=0')
End
PosX=P.Num4
PosX=PosX.PosX
Call ToPipe('define bitmap anim 'PosX''XY)
Call ToPipe('ID 'BP.Num4' ni=0')
Call ToPipe('ID 'MG' gt="'Move2'"')
End
Return 0
Buttons:
IF Dis="" THEN DO
Dis=" ro";Dis2=""
Piece='anim 121'XY;Piece2='anim 151'XY
End
ELSE DO
Dis="";Dis2=" ro"
Piece='anim 151'XY;Piece2='anim 121'XY
End
Call ToPipe(' layout b=0 sw')
Call ToPipe(' button minw=29 ro b=0 gt="'Let.i'"')
GadNum=ToPipe(' button'Dis' b=0 'Piece2)
Call ToPipe(' button'Dis2' b=0 'Piece)
DO a=1 TO 3
Call ToPipe(' button'Dis' b=0 'Piece2)
Call ToPipe(' button'Dis2' b=0 'Piece)
End
Call ToPipe(' button minw=29 ro b=0 gt="'Let.i'"')
Call ToPipe(' le')
IF Dis=" ro" THEN GadNum=GadNum+1
DO a=1 TO 4
GP.GadNum=Num
BP.Num=GadNum
Num=Num+1
GadNum=GadNum+2
End
Return 0
Nums:
Call ToPipe(' layout b=0 sw')
Call ToPipe(' button minw=29 ro b=0 gt=""')
DO i=1 TO 8
Call ToPipe(' button minw=29 ro b=0 gt="'i'"')
End
Call ToPipe(' button minw=29 ro b=0 gt=""')
Call ToPipe(' le')
Return 0
Pieces:
DO i=1 TO 32
PosX=P.i
PosX=PosX.PosX
Call ToPipe('define bitmap anim 'PosX''XY)
Call ToPipe('ID 'BP.i' ni=0')
End
Return 0
NewGame:
IF ~Open(PIPE2,"AWNPipe:RXDraughts2/xc","RW") THEN DO
SAY "Unable to open GUI, please install AWNPipe:"
Exit
End
TPipe="PIPE2"
Call ToPipe('title "New Game" v m defg')
Call ToPipe('layout gt="Player options" so v')
PG=ToPipe(' radiobutton rl="Two human players|Against the computer|Watch the computer|Online multiplayer"')
Call ToPipe('le')
Call ToPipe('space')
Call ToPipe('layout gt="Load game" so')
Call ToPipe(' layout v b=0')
Call ToPipe(' label gt="Next player"')
Call ToPipe(' space')
PG2=ToPipe(' radiobutton rl="Black|Yellow"')
Call ToPipe(' le')
Call ToPipe(' space')
Call ToPipe(' label gt="File: " ua')
FG=ToPipe(' getfile chl')
Call ToPipe('le')
Call ToPipe('space')
Call ToPipe('layout gt="Online options" so')
Call ToPipe(' layout v b=0')
Call ToPipe(' label gt="Player"')
Call ToPipe(' space')
PG3=ToPipe(' radiobutton rl="One|Two"')
Call ToPipe(' le')
Call ToPipe(' space')
Call ToPipe(' label gt="IP: " ua')
HG=ToPipe(' string lj chl')
Call ToPipe('le')
SG=ToPipe('button gt="Start"')
Call ToPipe('open')
Start="0";Opt="1"
IP="";Play="B"
TFile="";Plr=""
DO UNTIL Start="1"
Call ToPipe('con')
Output=ReadLn(PIPE2)
Parse Var Output W1" "W2" "W3" 1 "W4
IF W1="close" THEN Call Break_C()
IF W2=PG THEN Opt=W3+1
IF W2=PG2 THEN DO
IF W3="0" THEN Play="B"
ELSE Play="W"
End
IF W2=FG THEN TFile=Strip(Left(W4,Length(W4)-1),,d2c(34))
IF W2=PG3 THEN Plr=W3+1
IF W2=HG THEN IP=W3
IF W2=SG THEN DO
IF Opt="4"&IP="" THEN Call rtezrequest("You must enter an IP address!")
ELSE Start="1"
End
End
IF Plr="" THEN Plr="1"
IF Opt<4 THEN Plr=""
Call Close(PIPE2)
Return 0
ToPipe:
Call WriteLn(TPipe,Arg(1))
Output=ReadLn(TPipe)
Parse Var Output W1" "Word2" "W3
IF Word(Output,1)="close" THEN Call Break_C()
Return Word2
FMove:
SAY ""
IF CJump="1" THEN DO
SAY "Checking for another jump with the same piece."
TheSqs=Num4
End
ELSE DO
IF Play="B" THEN Colour="black"
ELSE Colour="white"
SAY "Finding squares with "colour" pieces.."
TheSqs=""
DO i=1 TO 32
IF Play="B"&Upper(P.i)="B" THEN TheSqs=TheSqs""i" "
IF Play="W"&Upper(P.i)="W" THEN TheSqs=TheSqs""i" "
End
IF TheSqs="" THEN DO
SAY "No "colour" squares found.."
End="1"
End
ELSE DO
SAY "Squares with "colour" pieces are "TheSqs
SAY "Finding moveable pieces.."
End
End
Words=Words(TheSqs)
ValidSqs="";ValidJps=""
IF End~="1" THEN DO i=1 TO Words
TheSq=Word(TheSqs,i)
King="0"
IF Upper(P.TheSq)=P.TheSq THEN King="1"
Call Grid2(TheSq)
Call Grid(Let+1""Num-1);NextSq=GNum2
Call Grid(Let+1""Num+1);NextSq2=GNum2
Call Grid(Let+2""Num-2);NextSq3=GNum2
Call Grid(Let+2""Num+2);NextSq4=GNum2
Call Grid(Let-1""Num-1);NextSq5=GNum2
Call Grid(Let-1""Num+1);NextSq6=GNum2
Call Grid(Let-2""Num-2);NextSq7=GNum2
Call Grid(Let-2""Num+2);NextSq8=GNum2
TP.TheSq="";TJP.TheSq=""
IF Play="W" THEN DO
Play2="B"
Piece=King;Piece2="1"
End
ELSE DO
Play2="W"
Piece="1";Piece2=King
End
IF Upper(P.NextSq)=Play2&P.NextSq3=""&King=Piece THEN TJP.TheSq=TJP.TheSq""TheSq"/"NextSq"/"NextSq3" "
IF Upper(P.NextSq2)=Play2&P.NextSq4=""&King=Piece THEN TJP.TheSq=TJP.TheSq""TheSq"/"NextSq2"/"NextSq4" "
IF Upper(P.NextSq5)=Play2&P.NextSq7=""&King=Piece2 THEN TJP.TheSq=TJP.TheSq""TheSq"/"NextSq5"/"NextSq7" "
IF Upper(P.NextSq6)=Play2&P.NextSq8=""&King=Piece2 THEN TJP.TheSq=TJP.TheSq""TheSq"/"NextSq6"/"NextSq8" "
IF P.NextSq=""&King=Piece THEN TP.TheSq=TP.TheSq""NextSq" "
IF P.NextSq2=""&King=Piece THEN TP.TheSq=TP.TheSq""NextSq2" "
IF P.NextSq5=""&King=Piece2 THEN TP.TheSq=TP.TheSq""NextSq5" "
IF P.NextSq6=""&King=Piece2 THEN TP.TheSq=TP.TheSq""NextSq6" "
IF TP.TheSq~="" THEN ValidSqs=ValidSqs""TheSq" "
IF TJP.TheSq~="" THEN DO
Jump="1"
ValidJps=ValidJps""TheSq" "
End
End
IF CJump~="1"&End~="1" THEN DO
IF ValidSqs=""&ValidJps="" THEN DO
SAY "No moveable pieces found.."
End="1"
End
ELSE SAY "Moveable pieces are "ValidSqs""ValidJps
End
Return 0
Vacant:
IF P.Num4~="" THEN DO
SAY "Invalid move. You must move to a vacant square."
Error="1"
End
Return 0
Grid:
GLet=Left(Arg(1),1);GNum=SubStr(Arg(1),2,1)
IF GLet<1|GLet>8|GNum<1|GNum>8 THEN GNum2="."
ELSE DO
GNum2=GNum/2
IF Right(GNum2,2)=".5" THEN GNum2=GNum2+0.5
Parse Var GNum2 GNum2"."Decimal
GNum2=(GLet*4-4)+GNum2
End
Return 0
Grid2:
Let=Arg(1)
Let=Let/4+1
Parse Var Let Let"."Decimal
IF Decimal="25" THEN Num="1"
IF Decimal="5" THEN Num="3"
IF Decimal="75" THEN Num="5"
IF Decimal="" THEN DO
Let=Let-1
Num="7"
End
IF Pos(".",Let/2)>0 THEN Num=Num+1
Return 0
Halt:
Break_C:
IF Opt="4"&Plr="2" THEN DO
Call Open(TCP,"TCP:localhost/998","R")
Call Close(TCP)
End
IF Move="EOF" THEN SAY "Opponent has quit the game.."
IF Plr="1"&Play="B"|Plr="2"&Play="W" THEN IF Open(TCP,"TCP:"IP"/998","W") THEN Call WriteLn(TCP,"EOF")
SAY "***Break"
Call Close(TPipe)
Exit